﻿package mortal.game.view.rebate.dayRecharge
{
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.item.*;
    import mortal.mvc.core.*;

    public class RebateDayRechargePanel extends RebateTopPanel
    {
        protected var _list:GTileList;
        protected var _reBtn:GLoadingButton;
        protected var _moneyIcon:GBitmap;
        protected var _totalM:GTextFiled;
        protected var _repTip:GBitmap;
        private var _isLoad:Boolean = false;

        public function RebateDayRechargePanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            _bg = UIFactory.gImageBitmap(ImagesConst.RebatePanelBgDayRecharge, 0, 0);
            this.addChildAt(_bg, 0);
            LoaderHelp.addResCallBack(ResFileConst.rebateDayRecharge, this.onResLoadRe);
            return;
        }// end function

        private function onResLoadRe() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this._isLoad = true;
            _day.x = 215;
            _day.y = 122;
            _hour.x = 269;
            _hour.y = 122;
            _min.x = 340;
            _min.y = 122;
            _sec.x = 392;
            _sec.y = 122;
            _dayTip.visible = false;
            this._list = UIFactory.tileList(56, 194, 795, 399, this);
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.verticalGap = 2;
            this._list.horizontalGap = 2;
            this._list.rowHeight = 57;
            this._list.columnWidth = 780;
            this._list.columnCount = 1;
            this._list.rowCount = 7;
            this._list.width = 795;
            this._list.setStyle("cellRenderer", RebateDayRechargeCell2);
            this._reBtn = UIFactory.gLoadingButton(ImagesConst.RebateDayRechargeOpenPage2_upSkin, 728, 130, 141, 40, this);
            this._reBtn.label = "";
            this._moneyIcon = UIFactory.gBitmap(ImagesConst.Yuanbao, 524, 189, this);
            this._totalM = UIFactory.gTextField("", 651, 94, 160, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setBold(true));
            this._repTip = UIFactory.gBitmap(ImagesConst.RebateDayRechargeRepeat, 717, 325, this);
            this._moneyIcon.visible = false;
            _activeTime.text = "";
            _actRule.text = "";
            _activeTime.x = 3;
            _actRule.x = 3;
            this.setData();
            this._reBtn.configEventListener(MouseEvent.CLICK, this.onGoToRechargeHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._isLoad == false)
            {
                return;
            }
            this._isLoad = false;
            this._list = null;
            this._reBtn = null;
            this._moneyIcon = null;
            this._totalM = null;
            this._repTip = null;
            _bg = null;
            return;
        }// end function

        public function setData() : void
        {
            var _loc_1:* = RebateUtil.getDayRechargeList();
            if (_loc_1.length > 0)
            {
                this._list.dataProvider = new DataProvider(_loc_1);
                this._list.drawNow();
                this.scrollToCanGet();
            }
            this._totalM.text = Language.getString(71775) + Cache.instance.rebate.rechargeSum;
            this.setTimeCountDown();
            return;
        }// end function

        public function getRewardBack(param1:int) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:RebateDayRechargeCell2 = null;
            if (this._list && this._list.dataProvider)
            {
                _loc_2 = 0;
                while (_loc_2 < this._list.dataProvider.length)
                {
                    
                    _loc_3 = this._list.getItemAt(_loc_2);
                    if (_loc_3)
                    {
                        _loc_4 = RebateUtil.dayRechargeArr[_loc_3.index];
                        if (_loc_4 != param1)
                        {
                        }
                        else
                        {
                            _loc_5 = this._list.itemToCellRenderer(_loc_3) as RebateDayRechargeCell2;
                            _loc_5.updateBtn();
                            _loc_5.flyIcon(_loc_4);
                            break;
                        }
                    }
                    _loc_2++;
                }
                this.scrollToCanGet();
            }
            this.closeGuidePanel();
            return;
        }// end function

        private function closeGuidePanel() : void
        {
            if (AutoGuideCache.isGuideFuncPanel)
            {
                if (Cache.instance.rebate.dayRechargeInfo == null)
                {
                    return;
                }
                if (this.hasGift() == false)
                {
                    GameController.rebate.view.hide();
                }
            }
            return;
        }// end function

        private function hasGift() : Boolean
        {
            var _loc_4:Object = null;
            var _loc_5:Array = null;
            var _loc_1:* = RebateUtil.getDayRechargeList();
            var _loc_2:* = Cache.instance.rebate.dayRechargeInfo.recharge;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_3];
                _loc_5 = RebateUtil.getRwState(_loc_4.index);
                return _loc_5[0] == 1;
                _loc_3++;
            }
            return false;
        }// end function

        private function onGoToRechargeHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateDayRechargeGoToRecharge));
            return;
        }// end function

        private function scrollToCanGet() : void
        {
            var _loc_2:RebateDayRechargeCell2 = null;
            if (this._list == null || this._list.dataProvider == null)
            {
                return;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this._list.dataProvider.length)
            {
                
                _loc_2 = this._list.itemToCellRenderer(this._list.getItemAt(_loc_1)) as RebateDayRechargeCell2;
                if (_loc_2)
                {
                    if (_loc_2.canGetReward())
                    {
                        this._list.scrollToIndex(_loc_1);
                        break;
                    }
                }
                _loc_1++;
            }
            return;
        }// end function

    }
}
